package io.renren.wechat.service.impl;

import com.alibaba.druid.util.StringUtils;
import io.renren.wechat.entity.UsersEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.wechat.dao.ChatMsgDao;
import io.renren.wechat.entity.ChatMsgEntity;
import io.renren.wechat.service.ChatMsgService;


@Service("chatMsgService")
public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgDao, ChatMsgEntity> implements ChatMsgService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<ChatMsgEntity> page = this.page(
//                new Query<ChatMsgEntity>().getPage(params),
//                new QueryWrapper<ChatMsgEntity>()
//        );
//
//        return new PageUtils(page);
//    }
        QueryWrapper<ChatMsgEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (!StringUtils.isEmpty(key)){
            wrapper.eq("id",key)
                    .or().eq("send_user_id",key)
                    .or().eq("accept_user_id",key)
                    .or().like("msg",key)
            ;
        }
        IPage<ChatMsgEntity> page = this.page(
                new Query<ChatMsgEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}